package ${packageName}.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lenovo.bloom.tool.common.api.exp.ServiceException;
import ${packageName}.common.enums.BloomErrorEnum;
import ${packageName}.model.entity.${classInfo.className};
import ${packageName}.repository.I${classInfo.className}DaoService;
import ${packageName}.service.I${classInfo.className}Service;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.*;

/**
 * ${classInfo.classComment} 实现类
 *
 * @author ${authorName}
 */
@AllArgsConstructor
@Service
public class ${classInfo.className}ServiceImpl implements I${classInfo.className}Service {

    private final I${classInfo.className}DaoService ${classInfo.className?uncap_first}DaoService;

    @Override
    public ${classInfo.className} get${classInfo.className}ById(${classInfo.pkClass} id) {
        return ${classInfo.className?uncap_first}DaoService.getById(id);
    }

    @Override
    public IPage get${classInfo.className}Page(Page page, ${classInfo.className} ${classInfo.className?uncap_first}) {
        return ${classInfo.className?uncap_first}DaoService.page(page, Wrappers.lambdaQuery(${classInfo.className?uncap_first}).orderByDesc(${classInfo.className}::getCreateTime));
    }

    @Override
    public String save${classInfo.className}(${classInfo.className} ${classInfo.className?uncap_first}) {
        ${classInfo.className?uncap_first}DaoService.save(${classInfo.className?uncap_first});
        return String.valueOf(${classInfo.className?uncap_first}.get${classInfo.pkField?cap_first}());
    }

    @Override
    public boolean update${classInfo.className}(${classInfo.className} ${classInfo.className?uncap_first}) {
        if (Objects.isNull(${classInfo.className?uncap_first}.get${classInfo.pkField?cap_first}())) {
            throw new ServiceException(BloomErrorEnum.e_0021.getCode(), BloomErrorEnum.e_0021.getMsg());
        }
        return ${classInfo.className?uncap_first}DaoService.updateById(${classInfo.className?uncap_first});
    }

    @Override
    public void remove${classInfo.className}ById(${classInfo.pkClass} id) {
        ${classInfo.className?uncap_first}DaoService.removeById(id);
    }

}
